package com.lwlk.zdk.controller.Enterprise;

import com.lwlk.zdk.annotation.JwtIgnore;
import com.lwlk.zdk.enums.RetCode;
import com.lwlk.zdk.mapper.T.*;
import com.lwlk.zdk.mapper.sys.sysEnterpriseMapper;
import com.lwlk.zdk.model.Excel.ErrorMessage;
import com.lwlk.zdk.model.T.TDisEnterprise;
import com.lwlk.zdk.model.T.TDisEnterprisePlatform;
import com.lwlk.zdk.model.T.TDisVehicle;
import com.lwlk.zdk.model.sys.sysEnterprise;
import com.lwlk.zdk.model.sys.sysUser;
import com.lwlk.zdk.util.POIUtil;
import com.lwlk.zdk.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(value = "业户的excel信息")
@RestController
@RequestMapping(value = "/excelEnterprise")
public class ExcelEnterpriseController {

    @Autowired
    TDisEnterpriseMapper disEnterpriseMapper;
    @Autowired
    private TDisDictionaryMapper disDictionaryMapper;
    @Autowired
    private TRegionMapper regionMapper;
    @Autowired
    private TDisPlatformMapper disPlatformMapper;
    @Autowired
    private TDisVehicleMapper disVehicleMapper;
    @Autowired
    private TDisEnterprisePlatformMapper disEnterprisePlatformMapper;
    @Autowired
    TDisVehicleMapper tDisVehicleMapper;

    @ApiOperation(value = "导入业户信息")
    @RequestMapping(value = "/IntoExcel", method = RequestMethod.POST)
    @JwtIgnore
    public Response IntoExcel(MultipartFile file) {

        Response response = new Response();
        Workbook workbook = POIUtil.getWorkBook(file);
        String fileName = file.getOriginalFilename();
        int errorCount = 0;/* 初始化错误条数 */
        int successCount = 0;/* 初始化错误条数 */
        List<ErrorMessage> errorMessages = new ArrayList<>();
        ErrorMessage errorMessage = null;
        try {
        if (fileName.endsWith("xls")) {
            // workbook = new HSSFWorkbook(is);
            Sheet shto = workbook.getSheetAt(0);
            for (Row row : shto) {
                if (row.getRowNum() < 1) {
                    continue;
                }
                String regionCodeName = row.getCell(1).getStringCellValue();//所属地区
                Integer regionCode = regionMapper.selectByCodeName(regionCodeName);//所属地区
                String industryName = row.getCell(2).getStringCellValue();//所属行业名称
                String organizationName = row.getCell(3).getStringCellValue();//所属管辖机构
                organizationName = organizationName.substring(0, organizationName.length() - 3);
                Integer organizationCode = regionMapper.selectByCodeName(organizationName);//管辖机构code
                Integer industryCode = null;//所属行业
                List<Map<String, Object>> industry = disDictionaryMapper.selectAll(null, industryName, null);
                if (industry.size() > 0) {
                    industryCode = Integer.valueOf(String.valueOf(industryName));
                } else {
                    industryCode = null;
                }
                String managementFormsName = row.getCell(4).getStringCellValue();
                Integer managementForms = null;
                if (managementFormsName.equals("营运")) {
                    managementForms = 0;
                } else {
                    managementForms = 1;
                }
                //业户信息
                String enterpriseName = row.getCell(0).getStringCellValue();
                if (enterpriseName != null) {
                    List<Map> enterpriseOne = disEnterpriseMapper.selectEnterpriseNameList(enterpriseName);
                    if (enterpriseOne.size() == 0) {
                        //创建实体类
                        TDisEnterprise disEnterprise = new TDisEnterprise();
                        Integer enterpriseId = disEnterpriseMapper.selectMaxEnterpriseId() + 1;
                        disEnterprise.setEnterpriseId(enterpriseId);
                        disEnterprise.setEnterpriseName(enterpriseName);//业户名称
                        disEnterprise.setRegionCode(regionCode);//所属地区
                        disEnterprise.setIndustryId(industryCode);//所属行业
                        disEnterprise.setOrganizationId(organizationCode);//管辖机构
                        disEnterprise.setManagementForms(managementForms);//经营状态
                        disEnterprise.setScope(row.getCell(5).getStringCellValue());//经营范围
                        disEnterprise.setSource(1);
                        disEnterprise.setDelFlag((short) 1);
                        int i = disEnterpriseMapper.insertSelective(disEnterprise);
                        successCount++;/* 成功条数统计 */
                    } else {
                        /* 封装错误信息 */
                        errorMessage = new ErrorMessage();
                        errorMessage.setVehicleNumber(row.getCell(0).getStringCellValue());
                        errorMessage.setVehicleLicenseColor(row.getCell(1).getStringCellValue());
                        errorMessage.setAdministrationOrgniaztion(row.getCell(2).getStringCellValue());
                        errorMessage.setIndustry(row.getCell(3).getStringCellValue());
                        errorMessage.setMessage("业户名信息已存在!(请修改后删除此提示信息重新导入)");
                        errorMessages.add(errorMessage);
                        errorCount++;/* 用户名重复条数统计 */
                    }
                } else {
                    /* 封装错误信息 */
                    errorMessage = new ErrorMessage();
                    errorMessage.setMessage("导入数据存中在空数据!(请修改后删除此提示信息重新导入)");
                    errorMessages.add(errorMessage);
                    errorCount++;/* 数据有空的项统计 */
                }
            }
        }
            if (fileName.endsWith("xlsx")) {
                //  workbook = new XSSFWorkbook(is);
                Sheet shto = workbook.getSheetAt(0);
                for (Row row : shto) {
                    if (row.getRowNum() < 1) {
                        continue;
                    }
                    String regionCodeName = row.getCell(1).getStringCellValue();//所属地区
                    Integer regionCode = regionMapper.selectByCodeName(regionCodeName);//所属地区
                    String industryName = row.getCell(2).getStringCellValue();//所属行业名称
                    String organizationName = row.getCell(3).getStringCellValue();//所属管辖机构
                    organizationName = organizationName.substring(0, organizationName.length() - 3);
                    Integer organizationCode = regionMapper.selectByCodeName(organizationName);//管辖机构code
                    Integer industryCode = null;//所属行业
                    List<Map<String, Object>> industry = disDictionaryMapper.selectAll(null, industryName, null);
                    if (industry.size() > 0) {
                        industryCode = Integer.valueOf(String.valueOf(industry.get(0).get("itemValue")));
                    } else {
                        industryCode = null;
                    }
                    String managementFormsName = row.getCell(4).getStringCellValue();
                    Integer managementForms = null;
                    if (managementFormsName.equals("营运")) {
                        managementForms = 0;
                    } else {
                        managementForms = 1;
                    }
                    //业户信息
                    String enterpriseName = row.getCell(0).getStringCellValue();
                    if (enterpriseName != null) {
                        List<Map> enterpriseOne = disEnterpriseMapper.selectEnterpriseNameList(enterpriseName);
                        if (enterpriseOne.size() == 0) {
                            //创建实体类
                            TDisEnterprise disEnterprise = new TDisEnterprise();
                            Integer enterpriseId = disEnterpriseMapper.selectMaxEnterpriseId() + 1;
                            disEnterprise.setEnterpriseId(enterpriseId);
                            disEnterprise.setEnterpriseName(enterpriseName);//业户名称
                            disEnterprise.setRegionCode(regionCode);//所属地区
                            disEnterprise.setIndustryId(industryCode);//所属行业
                            disEnterprise.setOrganizationId(organizationCode);//管辖机构code
                            disEnterprise.setManagementForms(managementForms);//经营状态
                            disEnterprise.setScope(row.getCell(5).getStringCellValue());//经营范围
                            disEnterprise.setSource(1);
                            disEnterprise.setDelFlag((short) 1);
                            int i = disEnterpriseMapper.insertSelective(disEnterprise);
                        } else {
                            /* 封装错误信息 */
                            errorMessage = new ErrorMessage();
                            errorMessage.setVehicleNumber(row.getCell(0).getStringCellValue());
                            errorMessage.setVehicleLicenseColor(row.getCell(1).getStringCellValue());
                            errorMessage.setAdministrationOrgniaztion(row.getCell(2).getStringCellValue());
                            errorMessage.setIndustry(row.getCell(3).getStringCellValue());
                            errorMessage.setMessage("业户名信息已存在!(请修改后删除此提示信息重新导入)");
                            errorMessages.add(errorMessage);
                            errorCount++;/* 用户名重复条数统计 */
                        }
                    } else {
                        /* 封装错误信息 */
                        errorMessage = new ErrorMessage();
                        errorMessage.setMessage("导入数据存中在空数据!(请修改后删除此提示信息重新导入)");
                        errorMessages.add(errorMessage);
                        errorCount++;/* 数据有空的项统计 */
                    }
                }
            }
            response.setCode(RetCode.SUCCESS);
            response.setMsg("执行成功");
        }catch (Exception e){
            e.printStackTrace();
            response.setMsg("所填信息有为空的信息,请重新导入");
        } finally {
            if (errorMessages != null) {
                response.setData(errorMessages);
            }
        }
        return response;
    }


        @ApiOperation(value = "导入接入业户信息")
        @RequestMapping(value = "/IntoJoinExcel", method = RequestMethod.POST)
        @JwtIgnore
        public Response IntoJoinExcel (MultipartFile file){
            Response response = new Response();
            int errorCount = 0;/* 初始化错误条数 */
            int successCount = 0;/* 初始化错误条数 */
            List<ErrorMessage> errorMessages = new ArrayList<>();
            ErrorMessage errorMessage = null;

            try {
                Workbook workbook = POIUtil.getWorkBook(file);
                String fileName = file.getOriginalFilename();
                if (fileName.endsWith("xls")) {
                    // workbook = new HSSFWorkbook(is);
                    Sheet shto = workbook.getSheetAt(0);
                    for (Row row : shto) {
                        if (row.getRowNum() < 1) {
                            continue;
                        }
                        String regionCodeName = row.getCell(1).getStringCellValue();//所属地区
                        Integer regionCode = regionMapper.selectByCodeName(regionCodeName);//所属地区
                        String industryName = row.getCell(2).getStringCellValue();//所属行业名称
                        String platformName = row.getCell(6).getStringCellValue();//平台名称
                        List<Map>platformId=disPlatformMapper.selectPlatformIdsList(platformName);
                        Integer industryCode = null;//所属行业
                        List<Map<String, Object>> industry = disDictionaryMapper.selectAll(null, industryName, null);
                        if (industry.size() > 0) {
                            industryCode = Integer.valueOf(String.valueOf(industryName));
                        } else {
                            industryCode = null;
                        }
                        String managementFormsName = row.getCell(4).getStringCellValue();
                        Integer managementForms = null;
                        if (managementFormsName.equals("营运")) {
                            managementForms = 0;
                        } else {
                            managementForms = 1;
                        }
                        String organizationName = row.getCell(3).getStringCellValue();
                        String organizationId = organizationName.substring(0, organizationName.length() - 3);
                        Integer organizationCode = regionMapper.selectByCodeName(organizationId);//管辖地区
                        List<Map> platformIdsList = disEnterpriseMapper.selectEnterpriseNameList(String.valueOf(row.getCell(0).getStringCellValue()));
                        if (platformIdsList.size() == 0) {
                            //创建实体类
                            TDisEnterprise disEnterprise = new TDisEnterprise();
                            Integer enterpriseId = disEnterpriseMapper.selectMaxEnterpriseId() + 1;
                            disEnterprise.setEnterpriseId(enterpriseId);
                            disEnterprise.setEnterpriseName(row.getCell(0).getStringCellValue());//业户名称
                            disEnterprise.setRegionCode(regionCode);//所属地区
                            disEnterprise.setIndustryId(industryCode);//所属行业
                            disEnterprise.setOrganizationId(organizationCode);//管辖机构
                            disEnterprise.setManagementForms(managementForms);//经营状态
                            disEnterprise.setScope(row.getCell(5).getStringCellValue());//经营范围
                            disEnterprise.setSource(1);
                            disEnterprise.setDelFlag((short) 1);
                            TDisEnterprisePlatform disEnterprisePlatform=new TDisEnterprisePlatform();
                            disEnterprisePlatform.setEnterpriseId(enterpriseId);
                            disEnterprisePlatform.setPlatformId(Integer.valueOf(String.valueOf(platformId.get(0).get("platform_id"))));
                            int count=disEnterprisePlatformMapper.selectOne(disEnterprisePlatform);
                            int i;
                            if (count==0){
                                i=disEnterprisePlatformMapper.insert(disEnterprisePlatform);
                            }else {
                                i=disEnterprisePlatformMapper.updatePlatform(disEnterprisePlatform);
                            }
                            disEnterpriseMapper.insertSelective(disEnterprise);
                            successCount++;/* 成功条数统计 */
                        } else {
                            /* 封装错误信息 */
                            errorMessage = new ErrorMessage();
                            errorMessage.setVehicleNumber(row.getCell(0).getStringCellValue());
                            errorMessage.setVehicleLicenseColor(row.getCell(1).getStringCellValue());
                            errorMessage.setAdministrationOrgniaztion(row.getCell(2).getStringCellValue());
                            errorMessage.setIndustry(row.getCell(3).getStringCellValue());
                            errorMessage.setMessage("业户名称已存在!(请修改后删除此提示信息重新导入)");
                            errorMessages.add(errorMessage);
                            errorCount++;/* 业户名重复条数统计 */
                        }
                    }
                }
                if (fileName.endsWith("xlsx")) {
                    //  workbook = new XSSFWorkbook(is);
                    Sheet shto = workbook.getSheetAt(0);
                    for (Row row : shto) {
                        if (row.getRowNum() < 1) {
                            continue;
                        }
                        String regionCodeName = row.getCell(1).getStringCellValue();//所属地区
                        Integer regionCode = regionMapper.selectByCodeName(regionCodeName);//所属地区
                        String industryName = row.getCell(2).getStringCellValue();//所属行业名称
                        String platformName = row.getCell(6).getStringCellValue();//平台名称
                        List<Map>platformId=disPlatformMapper.selectPlatformIdsList(platformName);
                        Integer industryCode = null;//所属行业
                        List<Map<String, Object>> industry = disDictionaryMapper.selectAll(null, industryName, null);
                        if (industry.size() > 0) {
                            industryCode = Integer.valueOf(String.valueOf(industry.get(0).get("itemValue")));
                        } else {
                            industryCode = null;
                        }
                        String managementFormsName = row.getCell(4).getStringCellValue();
                        Integer managementForms = null;
                        if (managementFormsName.equals("营运")) {
                            managementForms = 0;
                        } else {
                            managementForms = 1;
                        }
                        String organizationName = row.getCell(3).getStringCellValue();
                        String organizationId = organizationName.substring(0, organizationName.length() - 3);
                        Integer organizationCode = regionMapper.selectByCodeName(organizationId);//管辖地区
                        List<Map> platformIdsList = disEnterpriseMapper.selectEnterpriseNameList(String.valueOf(row.getCell(0).getStringCellValue()));
                        if (platformIdsList.size() == 0) {
                            //创建实体类
                            TDisEnterprise disEnterprise = new TDisEnterprise();
                            Integer enterpriseId = disEnterpriseMapper.selectMaxEnterpriseId() + 1;
                            disEnterprise.setEnterpriseId(enterpriseId);
                            disEnterprise.setEnterpriseName(row.getCell(0).getStringCellValue());//业户名称
                            disEnterprise.setRegionCode(regionCode);//所属地区
                            disEnterprise.setIndustryId(industryCode);//所属行业
                            disEnterprise.setOrganizationId(organizationCode);//管辖机构
                            disEnterprise.setManagementForms(managementForms);//经营状态
                            disEnterprise.setScope(row.getCell(5).getStringCellValue());//经营范围
                            disEnterprise.setSource(1);
                            disEnterprise.setDelFlag((short) 1);
                            TDisEnterprisePlatform disEnterprisePlatform=new TDisEnterprisePlatform();
                            disEnterprisePlatform.setEnterpriseId(enterpriseId);
                            disEnterprisePlatform.setPlatformId(Integer.valueOf(String.valueOf(platformId.get(0).get("platform_id"))));
                            int count=disEnterprisePlatformMapper.selectOne(disEnterprisePlatform);
                            int i;
                            if (count==0){
                                i=disEnterprisePlatformMapper.insert(disEnterprisePlatform);
                            }else {
                                i=disEnterprisePlatformMapper.updatePlatform(disEnterprisePlatform);
                            }
                             disEnterpriseMapper.insertSelective(disEnterprise);
                            successCount++;/* 成功条数统计 */
                        } else {
                            /* 封装错误信息 */
                            errorMessage = new ErrorMessage();
                            errorMessage.setVehicleNumber(row.getCell(0).getStringCellValue());
                            errorMessage.setVehicleLicenseColor(row.getCell(1).getStringCellValue());
                            errorMessage.setAdministrationOrgniaztion(row.getCell(2).getStringCellValue());
                            errorMessage.setIndustry(row.getCell(3).getStringCellValue());
                            errorMessage.setMessage("业户名称已存在!(请修改后删除此提示信息重新导入)");
                            errorMessages.add(errorMessage);
                            errorCount++;/* 业户名重复条数统计 */
                        }
                    }
                }
                response.setCode(RetCode.SUCCESS);
            } catch (Exception e) {
                e.printStackTrace();
                response.setMsg("所填信息有为空的信息,请重新导入");
            } finally {
                if (errorMessages != null) {
                    response.setData(errorMessages);
                }
            }
            return response;
        }

    @ApiOperation(value = "接入车辆信息excel表格导入接口")
    @RequestMapping(value = "/IntojoinVehicleExcel",method = RequestMethod.POST)
    @JwtIgnore
    public Response getIntoJoinExcel(MultipartFile file) throws Exception {

        Response response=new Response();
        int errorCount = 0;/* 初始化错误条数 */
        int successCount = 0;/* 初始化错误条数 */
        List<ErrorMessage> errorMessages =new ArrayList<>();
        ErrorMessage errorMessage=null;
        try {
            Workbook workbook= POIUtil.getWorkBook(file);
            System.out.println(workbook);
            String fileName = file.getOriginalFilename();
            if(fileName.endsWith("xls")){
                // workbook = new HSSFWorkbook(is);
                Sheet shto = workbook.getSheetAt(0);
                for (Row row : shto) {
                    if (row.getRowNum() < 1) {
                        continue;
                    }
                    String vehicleLicenseColorName=row.getCell(1).getStringCellValue();//车牌颜色
                    String administrationOrgniaztion=row.getCell(2).getStringCellValue();//管辖地区
                    String industryName=row.getCell(3).getStringCellValue();//所属行业名称
                    String regionCodeName=row.getCell(4).getStringCellValue();//所属地区
                    String vehicleType=row.getCell(5).getStringCellValue();//车辆类型
                    String enterpriseName=row.getCell(6).getStringCellValue();//业户名称
                    String platformName=row.getCell(7).getStringCellValue();//平台名称
                    String netStatus=row.getCell(8).getStringCellValue();//入网状态
                    //String onlineStatus=row.getCell(9).getStringCellValue();//在线状态
                    Integer platformId=null;
                    if (platformName!=null){
                        List<Map>platformIdsList=disPlatformMapper.selectPlatformIdsList(platformName);
                        if (platformIdsList.size()>0){
                            platformId= Integer.valueOf(String.valueOf(platformIdsList.get(0).get("platform_id")));
                        }
                    }
                    Integer netStatusInt=null;
                    Integer enterpriseId=null;
                    if (enterpriseName!=null){
                        List<Map>enterpriseNameList=disEnterpriseMapper.selectEnterpriseNameList(enterpriseName);
                        enterpriseId= Integer.valueOf(String.valueOf(enterpriseNameList.get(0).get("enterprise_id")));
                    }
                    if (netStatus.equals("已入网")){
                        netStatusInt=1;
                    }else {
                        netStatusInt=0;
                    }
                    Short vehicleLicenseColor=null;
                    List<Map<String,Object>>dictionary=disDictionaryMapper.selectAll(null,vehicleLicenseColorName,null);//车牌颜色
                    if (dictionary.size()>0){
                        vehicleLicenseColor= Short.valueOf(String.valueOf(dictionary.get(0).get("itemValue")));
                    }else {
                        vehicleLicenseColor=null;
                    }
                    administrationOrgniaztion=administrationOrgniaztion.substring(0,administrationOrgniaztion.length()-3);
                    Integer administrationOrgniaztionCode =regionMapper.selectByCodeName(administrationOrgniaztion);
                    List<Map<String,Object>>industry=disDictionaryMapper.selectAll(null,industryName,null);
                    Integer industryCode=null;//所属行业
                    if (industry.size()>0){
                        industryCode= Integer.valueOf(String.valueOf(industry.get(0).get("itemValue")));
                    }else {
                        industryCode=null;
                    }
                    Integer vehicleTypeCode=null;//车辆类型
                    List<Map<String,Object>>vehicleTypeName=disDictionaryMapper.selectAll(null,vehicleType,null);
                    if (vehicleTypeName.size()>0){
                        vehicleTypeCode= Integer.valueOf(String.valueOf(vehicleTypeName.get(0).get("itemValue")));
                    }else {
                        vehicleTypeCode=null;
                    }
                    Integer regionCode =regionMapper.selectByCodeName(regionCodeName);//所属地区
                    if (row.getCell(0).getStringCellValue()!=null){//如果车牌号不为空
                        List<TDisVehicle> disVehicles = disVehicleMapper.findUserByUsername(row.getCell(0).getStringCellValue());
                        if (disVehicles.size()==0){
                            //创建实体类
                            TDisVehicle disVehicle=new TDisVehicle();
                            Integer vehicleId=tDisVehicleMapper.selectMaxVehicleId()+1;
                            disVehicle.setVehicleId(vehicleId);
                            disVehicle.setVehicleNumber(row.getCell(0).getStringCellValue());//车牌号
                            disVehicle.setVehicleLicenseColor(vehicleLicenseColor);//车牌颜色
                            disVehicle.setAdministrationOrgniaztion(String.valueOf(administrationOrgniaztionCode));//管辖地区
                            disVehicle.setIndustryId(industryCode);//所属行业
                            disVehicle.setPlatformId(platformId);//所属平台
                            disVehicle.setRegionCode(regionCode);//所属地区
                            disVehicle.setVehicleType(vehicleTypeCode);//车辆类型
                            disVehicle.setEnterpriseId(enterpriseId);//业户id
                            disVehicle.setNetStatus(netStatusInt);
                            disVehicle.setSource(1);
                            disVehicle.setDelFlag((short) 1);
                            disVehicleMapper.insertSelective(disVehicle);
                            successCount++;/* 成功条数统计 */
                        }else {
                            /* 封装错误信息 */
                            errorMessage=new ErrorMessage();
                            errorMessage.setVehicleNumber(row.getCell(0).getStringCellValue());
                            errorMessage.setVehicleLicenseColor(row.getCell(1).getStringCellValue());
                            errorMessage.setAdministrationOrgniaztion(row.getCell(2).getStringCellValue());
                            errorMessage.setIndustry(row.getCell(3).getStringCellValue());
                            errorMessage.setMessage("车牌号信息已存在!(请修改后删除此提示信息重新导入)");
                            errorMessages.add(errorMessage);
                            errorCount++;/* 用户名重复条数统计 */
                        }
                    }else {
                        /* 封装错误信息 */
                        errorMessage = new ErrorMessage();
                        errorMessage.setMessage("导入数据存中在空数据!(请修改后删除此提示信息重新导入)");
                        errorMessages.add(errorMessage);
                        errorCount++;/* 数据有空的项统计 */
                    }
                }
            }
            if(fileName.endsWith("xlsx")){
                //  workbook = new XSSFWorkbook(is);
                Sheet shto = workbook.getSheetAt(0);
                for (Row row : shto) {
                    if (row.getRowNum() < 1) {
                        continue;
                    }
                    String vehicleLicenseColorName=row.getCell(1).getStringCellValue();//车牌颜色
                    String administrationOrgniaztion=row.getCell(2).getStringCellValue();//管辖地区
                    String industryName=row.getCell(3).getStringCellValue();//所属行业名称
                    String regionCodeName=row.getCell(4).getStringCellValue();//所属地区
                    String vehicleType=row.getCell(5).getStringCellValue();//车辆类型
                    String enterpriseName=row.getCell(6).getStringCellValue();//业户名称
                    String platformName=row.getCell(7).getStringCellValue();//平台名称
                    String netStatus=row.getCell(8).getStringCellValue();//入网状态
                    //String onlineStatus=row.getCell(9).getStringCellValue();//在线状态
                    Integer platformId=null;
                    if (platformName!=null){
                        List<Map>platformIdsList=disPlatformMapper.selectPlatformIdsList(platformName);
                        if (platformIdsList.size()>0){
                            platformId= Integer.valueOf(String.valueOf(platformIdsList.get(0).get("platform_id")));
                        }
                    }
                    Integer netStatusInt=null;
                    Integer enterpriseId=null;
                    if (enterpriseName!=null){
                        List<Map>enterpriseNameList=disEnterpriseMapper.selectEnterpriseNameList(enterpriseName);
                        enterpriseId= Integer.valueOf(String.valueOf(enterpriseNameList.get(0).get("enterprise_id")));
                    }
                    if (netStatus.equals("已入网")){
                        netStatusInt=1;
                    }else {
                        netStatusInt=0;
                    }
                    Short vehicleLicenseColor=null;
                    List<Map<String,Object>>dictionary=disDictionaryMapper.selectAll(null,vehicleLicenseColorName,null);//车牌颜色
                    if (dictionary.size()>0){
                        vehicleLicenseColor= Short.valueOf(String.valueOf(dictionary.get(0).get("itemValue")));
                    }else {
                        vehicleLicenseColor=null;
                    }
                    administrationOrgniaztion=administrationOrgniaztion.substring(0,administrationOrgniaztion.length()-3);
                    Integer administrationOrgniaztionCode =regionMapper.selectByCodeName(administrationOrgniaztion);
                    List<Map<String,Object>>industry=disDictionaryMapper.selectAll(null,industryName,null);
                    Integer industryCode=null;//所属行业
                    if (industry.size()>0){
                        industryCode= Integer.valueOf(String.valueOf(industry.get(0).get("itemValue")));
                    }else {
                        industryCode=null;
                    }
                    Integer vehicleTypeCode=null;//车辆类型
                    List<Map<String,Object>>vehicleTypeName=disDictionaryMapper.selectAll(null,vehicleType,null);
                    if (vehicleTypeName.size()>0){
                        vehicleTypeCode= Integer.valueOf(String.valueOf(vehicleTypeName.get(0).get("itemValue")));
                    }else {
                        vehicleTypeCode=null;
                    }
                    Integer regionCode =regionMapper.selectByCodeName(regionCodeName);//所属地区
                    if (row.getCell(0).getStringCellValue()!=null){//如果车牌号不为空
                        List<TDisVehicle> disVehicles = disVehicleMapper.findUserByUsername(row.getCell(0).getStringCellValue());
                        if (disVehicles.size()==0){
                            //创建实体类
                            TDisVehicle disVehicle=new TDisVehicle();
                            Integer vehicleId=tDisVehicleMapper.selectMaxVehicleId()+1;
                            disVehicle.setVehicleId(vehicleId);
                            disVehicle.setVehicleNumber(row.getCell(0).getStringCellValue());//车牌号
                            disVehicle.setVehicleLicenseColor(vehicleLicenseColor);//车牌颜色
                            disVehicle.setAdministrationOrgniaztion(String.valueOf(administrationOrgniaztionCode));//管辖地区
                            disVehicle.setIndustryId(industryCode);//所属行业
                            disVehicle.setPlatformId(platformId);//所属平台
                            disVehicle.setRegionCode(regionCode);//所属地区
                            disVehicle.setVehicleType(vehicleTypeCode);//车辆类型
                            disVehicle.setEnterpriseId(enterpriseId);//业户id
                            disVehicle.setNetStatus(netStatusInt);
                            disVehicle.setSource(1);
                            disVehicle.setDelFlag((short) 1);
                            disVehicleMapper.insertSelective(disVehicle);
                            successCount++;/* 成功条数统计 */
                        }else {
                            /* 封装错误信息 */
                            errorMessage=new ErrorMessage();
                            errorMessage.setVehicleNumber(row.getCell(0).getStringCellValue());
                            errorMessage.setVehicleLicenseColor(row.getCell(1).getStringCellValue());
                            errorMessage.setAdministrationOrgniaztion(row.getCell(2).getStringCellValue());
                            errorMessage.setIndustry(row.getCell(3).getStringCellValue());
                            errorMessage.setMessage("车牌号信息已存在!(请修改后删除此提示信息重新导入)");
                            errorMessages.add(errorMessage);
                            errorCount++;/* 用户名重复条数统计 */
                        }
                    }else {
                        /* 封装错误信息 */
                        errorMessage = new ErrorMessage();
                        errorMessage.setMessage("导入数据存中在空数据!(请修改后删除此提示信息重新导入)");
                        errorMessages.add(errorMessage);
                        errorCount++;/* 数据有空的项统计 */
                    }
                }
            }
            response.setCode(RetCode.SUCCESS);
            response.setMsg("执行成功");
        }catch (Exception e){
            e.printStackTrace();
            response.setCode(RetCode.ENTERPRISE_EXIST);
            response.setMsg("所填信息有为空的信息,请重新导入");
            return response;
        }finally {
            if (errorMessages!=null) {
                response.setData(errorMessages);
            }

        }
        return response;
    }


}

